class_name RegenerationEffect
extends Effect

# 持续治疗效果 - 每回合恢复生命值

# 可配置参数
var heal_amount: int = 5  # 每次恢复的生命值
var heal_sound: AudioStream  # 治疗音效

func execute(targets: Array[Node]) -> void:
	print("🌿 RegenerationEffect.execute() 被调用，恢复 %d 点生命值" % heal_amount)
	
	for target in targets:
		if not target or not is_instance_valid(target):
			continue
		if target is Player:
			_apply_healing(target)
			if heal_sound:
				SFXPlayer.play(heal_sound)
		else:
			print("❌ 目标不是Player类型: %s" % target.get_class())

func _apply_healing(player: Player) -> void:
	print("🌿 对玩家 %s 应用持续治疗效果" % player.name)
	
	# 获取玩家状态
	var stats = player.get_stats()
	if stats:
		var old_health = stats.health
		stats.health = min(stats.health + heal_amount, stats.max_health)
		var actual_heal = stats.health - old_health
		
		print("🌿 玩家 %s 生命值: %d -> %d (恢复 %d 点)" % [player.name, old_health, stats.health, actual_heal])
		
		# 触发治疗事件
		Events.player_healed.emit(player, actual_heal)
	else:
		print("❌ 无法获取玩家状态")

# 配置方法 - 允许外部设置参数
func configure(amount: int = 5, sound: AudioStream = null) -> void:
	self.heal_amount = amount
	self.heal_sound = sound
	print("⚙️ RegenerationEffect 配置完成：")
	print("  - 治疗量: %d" % heal_amount)
	print("  - 音效: %s" % ("已设置" if sound else "未设置")) 
